package com.zb.spring5;

import com.zb.spring5.ioc.entity.MessageEvent;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import sun.plugin2.message.Message;

public class Publisher implements ApplicationContextAware {
    private ApplicationContext ctx;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.ctx = applicationContext;
    }
    public void publish(String msg){
        ctx.publishEvent(new MessageEvent(this, msg));
    }

    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/app-content-xml.xml");
        Publisher publisher = (Publisher)ctx.getBean("publisher");
        publisher.publish("I send an SOS to the world");
        publisher.publish("I hope");
    }

}
